//
//  ASUserCenterController.m
//  AvatarShow
//
//  Created by xunruiIOS on 2021/4/27.
//

#import "ASUserCenterController.h"
#import "ASUserCenterCell.h"
#import "ASUserCenterModel.h"
#import "ASCollectionMianVC.h"
#import "ASSeetingController.h"
#import "ASMyWorkListVC.h"
#import "ASCollectionListSubVC.h"

@interface ASUserCenterController () <UITableViewDelegate,UITableViewDataSource>

@property (strong, nonatomic) UITableView *tableView;
@property (strong, nonatomic) NSMutableArray *dataArr;

@end

@implementation ASUserCenterController

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = YES;
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    self.navigationController.navigationBarHidden = NO;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor colorWithHexString:@"ffffff"];
    [self.view addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(UIEdgeInsetsMake(-Height_StatusBar, 0, 0, 0));
    }];
    [self createData];
    // Do any additional setup after loading the view.
}

- (void)createData{
    self.dataArr = [NSMutableArray new];
    NSArray *titleArr = @[@"我的作品",@"我的收藏",@"我的下载",@"设置"];
    NSArray *imageArr = @[@"me_zp",@"me_sc",@"me_xz",@"me_sz"];
    for (int x = 0; x < titleArr.count; x++) {
        ASUserCenterModel *model = [ASUserCenterModel new];
        model.imageStr = imageArr[x];
        model.titleStr = titleArr[x];
        [self.dataArr addObject:model];
    }
    [self.tableView reloadData];
}

- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectZero];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.backgroundColor = self.view.backgroundColor;
        _tableView.alwaysBounceVertical = YES;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        [_tableView registerClass:[ASUserCenterCell class] forCellReuseIdentifier:ASUserCenterCellStr];
        
        UIImageView *headV = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"me_bg"]];
        headV.contentMode = UIViewContentModeScaleAspectFill;
        headV.clipsToBounds = YES;
        headV.frame = CGRectMake(0, 0, SCREEN_WIDTH, 140+Height_StatusBar);
        _tableView.tableHeaderView = headV;
    }
    return _tableView;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArr.count;
}

- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 44;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ASUserCenterCell *cell = [tableView dequeueReusableCellWithIdentifier:ASUserCenterCellStr];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if (self.dataArr.count > indexPath.row) {
        cell.model = self.dataArr[indexPath.row];
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    cell.backgroundColor = [UIColor colorWithHexString:@"ffffff"];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        [self pushWorksListVC];
    }else if (indexPath.row == 1) {
        [self pushCollectVC];
    }else if (indexPath.row == 2) {
        [self pushDownloadVC];
    }else if (indexPath.row == 3) {
        [self pushSeetingVC];
    }
}

///跳转设置页面
- (void)pushSeetingVC{
    ASSeetingController *setVC = [ASSeetingController new];
    setVC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:setVC animated:YES];
}

///跳转收藏页面
- (void)pushCollectVC{
    [ASTool addUMTongJiKey:@"user_center" subKey:@"my" titleStr:@"我的收藏"];
    ASCollectionMianVC *subVC = [ASCollectionMianVC new];
    subVC.hidesBottomBarWhenPushed = YES;
    subVC.title = @"我的收藏";
    [self.navigationController pushViewController:subVC animated:YES];
    
//    ASCollectionListSubVC *vc = [ASCollectionListSubVC new];
//    vc.hidesBottomBarWhenPushed = YES;
//    [self.navigationController pushViewController:vc animated:YES];
}

///跳转我的作品页面
- (void)pushWorksListVC{
    [ASTool addUMTongJiKey:@"user_center" subKey:@"my" titleStr:@"我的作品"];
    ASMyWorkListVC *listVC = [ASMyWorkListVC new];
    listVC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:listVC animated:YES];
}

///跳转我的下载页面
- (void)pushDownloadVC{
    [ASTool addUMTongJiKey:@"user_center" subKey:@"my" titleStr:@"我的下载"];
    ASCollectionMianVC *subVC = [ASCollectionMianVC new];
    subVC.hidesBottomBarWhenPushed = YES;
    subVC.type = 1;
    subVC.title = @"我的下载";
    [self.navigationController pushViewController:subVC animated:YES];

}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
